package fristphase.day9_07.my_plane_battle;

import javax.swing.*;

public class HeroPlane extends FlyingObject{
    private int life = 3,fire = 0;
    HeroPlane(){
        super(97,139,(World.WIDTH-100)/2,World.HEIGHT-350,6);
    }
    public void step(){
    }
    int flag = 0;
    public ImageIcon getImage(){
        ImageIcon img = null;
        if(flag == 0){
            img = Images.heroPlanes[flag];
            flag = 1;
        }else if(flag == 1){
            img = Images.heroPlanes[flag];
            flag = 0;
        }
        return img;
    }
    //发射子弹功能
    public Bullet[] shootBullet(){
        int setY = y+40;

        Bullet[] bs;
        if(fire > 0){
            bs = new Bullet[2];
            bs[0] = new Bullet(x+8,setY);
            bs[1] = new Bullet(x+width-18,setY);
            fire -= 2;
        }else {
            bs = new Bullet[1];
            bs[0] = new Bullet(x+width/2-5,y);
        }
        return bs;
    }
    //英雄机移动
    public void moveTo(int x,int y){
        this.x = x-this.width/2;
        this.y = y-this.height/2;
    }
    //获取奖励
    public void getAward(int award){
          if(award==0){
              this.life += 1;
          }else if(award == 1){
              this.fire += 30;
          }
    }
    //减生命
    public void subtractLife(int life){
        this.life -= life;
    }
    //获取生命
    public int getLife(){
        return this.life;
    }
}
